Imports CasClientBase
Imports ccapps.persistent.MVPN_Lib
Imports ccapps.Util

Namespace Web.page

    Public Class MVPN_FreeVPN_Giris
        Inherits [lib].BasePage

        Protected WithEvents DefProf As System.Web.UI.HtmlControls.HtmlSelect
        Protected WithEvents custcode As System.Web.UI.WebControls.TextBox
        Protected WithEvents txt_VPNID As System.Web.UI.WebControls.TextBox
        Protected WithEvents btn_Search As System.Web.UI.WebControls.Button
        Protected WithEvents txt_NewVPNName As System.Web.UI.WebControls.TextBox
        Protected WithEvents btn_GetNewVPNID As System.Web.UI.WebControls.Button
        Protected WithEvents txtAveaPrefixNumber As System.Web.UI.WebControls.TextBox
        Protected WithEvents RegularExpressionValidator1 As System.Web.UI.WebControls.RegularExpressionValidator
        Protected WithEvents txtNonAveaPrefixNumber As System.Web.UI.WebControls.TextBox
        Protected WithEvents RegularExpressionValidator2 As System.Web.UI.WebControls.RegularExpressionValidator
        Protected WithEvents txt_Msisdn As System.Web.UI.WebControls.TextBox

#Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub
        Protected WithEvents ltlAlert As System.Web.UI.WebControls.Literal
        Protected WithEvents Button66 As System.Web.UI.WebControls.Button
        Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
        Protected WithEvents proc As System.Web.UI.HtmlControls.HtmlInputHidden
        'Protected WithEvents Button1 As System.Web.UI.HtmlControls.HtmlInputButton

        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub

#End Region

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'Put user code to initialize the page here
            ClearSessionParameters()

            If Session("MVPN_by_pass_tmcode_black_profile") = "" Then
                Dim l_dummy_MVPN_by_pass_tmcode_black_profile As String
                Get_Role_Control_Ability(Session("role_id"), l_dummy_MVPN_by_pass_tmcode_black_profile)
                Session("MVPN_by_pass_tmcode_black_profile") = l_dummy_MVPN_by_pass_tmcode_black_profile
            End If


            Me.PageTitle = "Free VPN Search/Define"
            Me.HelpDocName = ""
            Message = ""
        End Sub

        Private Sub btn_GetNewVPNID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_GetNewVPNID.Click
            Dim l_sonuc As String
            Dim l_new_vpnid As String
            If txt_NewVPNName.Text = "" Then
                Message = "alert('Not a valid VPN name.');"
                Return
            End If
            GetFreeVpn(l_new_vpnid)
            l_sonuc = PrepareNewVPN(l_new_vpnid, "FREEVPN_" + l_new_vpnid, txt_NewVPNName.Text, IIf(Me.txtAveaPrefixNumber.Text.Trim().Length = 0, "NULL", Me.txtAveaPrefixNumber.Text), IIf(Me.txtNonAveaPrefixNumber.Text.Trim().Length = 0, "NULL", Me.txtNonAveaPrefixNumber.Text))
            If l_sonuc = "OK" Then
                txt_VPNID.Text = l_new_vpnid
                Message = "alert('New VPNID is ready and saved int the VPNID box. You may continue.');"
            Else
                Message = "alert('" + l_sonuc + "');"
            End If
        End Sub

        Private Sub btn_Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Search.Click
            Dim l_sonuc As String
            If txt_VPNID.Text <> "" Then
                l_sonuc = CheckFreeVPN_VPNID(txt_VPNID.Text)
                If l_sonuc = "OK-FREEVPN" Then
                    'Session("MVPN_VPNID") = txt_VPNID.Text
                    Session("MVPN_VPNID") = txt_VPNID.Text
                    Session("MVPN_GirisSource") = "F"
                    Response.Redirect("MVPN_Anasayfa.aspx")
                ElseIf l_sonuc = "OK-COMPANYVPN" Then
                    Message = "alert('This is not a FREEVPN!');"
                Else
                    Message = "alert('" + l_sonuc + "');"
                End If
            ElseIf txt_Msisdn.Text <> "" Then
                l_sonuc = GetVPNIDFromMSISDN(txt_Msisdn.Text)
                If l_sonuc.StartsWith("HATA") Then
                    Message = "alert('" + l_sonuc + "');"
                Else
                    txt_VPNID.Text = l_sonuc
                    l_sonuc = CheckFreeVPN_VPNID(txt_VPNID.Text)
                    If l_sonuc = "OK-FREEVPN" Then
                        'Session("MVPN_VPNID") = txt_VPNID.Text
                        Session("MVPN_VPNID") = txt_VPNID.Text
                        Session("MVPN_MSISDN") = txt_Msisdn.Text
                        Session("MVPN_GirisSource") = "F"
                        Response.Redirect("MVPN_Anasayfa.aspx")
                    ElseIf l_sonuc = "OK-COMPANYVPN" Then
                        Message = "alert('This is not a FREEVPN!');"
                    Else
                        Message = "alert('" + l_sonuc + "');"
                    End If
                End If
            Else
                Message = "alert('No VPNID or MSISDN is selected!');"
            End If
        End Sub

        Private Sub ClearSessionParameters()
            Session("MVPN_CurrentPageIndex") = Nothing
            Session("MVPN_GirisSource") = Nothing
            Session("MVPN_GridSource") = Nothing
            Session("MVPN_InitialDataTable") = Nothing
            Session("MVPN_MSISDN") = Nothing
            Session("MVPN_Message") = Nothing
            Session("MVPN_MinCoidMsisdn") = Nothing
            Session("MVPN_PageSize") = Nothing
            Session("MVPN_TEKMSISDN_MSISDN") = Nothing
            Session("MVPN_TEKMSISDN_Message") = Nothing
            Session("MVPN_VPNID") = Nothing
            Session("MVPN_custcode") = Nothing
            Session("MVPN_defprof") = Nothing
            Session("MVPN_sme_la_flag") = Nothing
        End Sub

    End Class
End Namespace